package com.cuckoo.cuckoo_app2.business.Imp;

import com.cuckoo.cuckoo_app2.MyApplication;
import com.cuckoo.cuckoo_app2.business.TipsMessagBusiness;
import com.cuckoo.cuckoo_app2.dao.TipsMessag;
import com.cuckoo.cuckoo_app2.greendao.DaoSession;
import com.cuckoo.cuckoo_app2.greendao.TipsMessagDao;

import java.util.List;

public class TipsMessagBusinessImp implements TipsMessagBusiness {
    @Override
    public TipsMessag getById(String id) {
        DaoSession db = MyApplication.getInstances().getDaoSession();
        List<TipsMessag> list = db.getTipsMessagDao().queryBuilder().where(TipsMessagDao.Properties.Id.eq(id)).limit(1).list();
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public boolean updata(TipsMessag tipsMessag) {
        DaoSession db = MyApplication.getInstances().getDaoSession();
        db.getTipsMessagDao().update(tipsMessag);
        return true;
    }

    @Override
    public Long install(TipsMessag tipsMessag) {
        DaoSession db = MyApplication.getInstances().getDaoSession();
        Long i = db.getTipsMessagDao().insert(tipsMessag);
        return i;
    }

    @Override
    public List<TipsMessag> getAll() {
        DaoSession db = MyApplication.getInstances().getDaoSession();
        List<TipsMessag> list = db.getTipsMessagDao().queryBuilder().orderDesc(TipsMessagDao.Properties.Date).list();
        return list;
    }

    @Override
    public boolean delete(String id) {
        DaoSession db = MyApplication.getInstances().getDaoSession();
        TipsMessag tipsMessag = db.getTipsMessagDao().queryBuilder().where(TipsMessagDao.Properties.Id.eq(id)).unique();
        if (tipsMessag != null){
            db.getTipsMessagDao().delete(tipsMessag);
        }
        return true;
    }
}
